home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / reader_requests / wild / include / gcc / compiler.h next >
C/C++ Source or Header  |  2000-02-23  |  8KB  |  367 lines

  1. /*
  2. **      $VER: compiler.h 37.32 (12.5.98)
  3. **
  4. **      Compiler independent register (and SAS/C extensions) handling
  5. **
  6. **      (C) Copyright 1997-98 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #ifndef COMPILER_H
  11. #define COMPILER_H
  12.  
  13.  /* There have been problems how to define the seglist pointer
  14.     under AROS, AmigaOS or elsewhere. It may make sense to
  15.     use a new, global type definition for it. This is done here. */
  16.  
  17. #ifndef _AROS
  18. #include <dos/dos.h>
  19. #define SEGLISTPTR BPTR
  20. #else
  21. typedef struct SegList * SEGLISTPTR;
  22. #endif /* AROS */
  23.  
  24.  
  25. /* Basically, Amiga C compilers must reach the goal to be
  26.    as SAS/C compatible as possible. But on the other hand,
  27.    when porting AmigaOS to other platforms, one perhaps
  28.    can't expect GCC becoming fully SAS/C compatible...
  29.  
  30.    There are two ways to make your sources portable:
  31.  
  32.     - using non ANSI SAS/C statements and making these
  33.       "available" to the other compilers (re- or undefining)
  34.     - using replacements for SAS/C statements and smartly
  35.       redefining these for any compiler
  36.  
  37.    The last mentioned is the most elegant, but may require to
  38.    rewrite your source codes, so this compiler include file
  39.    basically does offer both.
  40.  
  41.    For some compilers, this may have been done fromout project or
  42.    makefiles for the first method (e.g. StormC) to ensure compileablity.
  43.  
  44.    Basically, you should include this header file BEFORE any other stuff.
  45. */
  46.  
  47. /* ********************************************************************* */
  48. /* Method 1: redefining SAS/C keywords                                   */
  49. /*                                                                       */
  50. /* Sorry, this method does not work with register definitions for the
  51. current gcc version (V2.7.2.1), as it expects register attributes after
  52. the parameter description. (This is announced to be fixed with gcc V2.8.0).
  53. Moreover the __asm keyword has another meaning with GCC. Therefore ASM
  54. must be used.
  55. */
  56.  
  57. #ifdef __MAXON__  // ignore this switches of SAS/Storm
  58. #define __aligned
  59. #define __asm
  60. #define __regargs
  61. #define __saveds
  62. #define __stdargs
  63. #endif
  64.  
  65. #ifdef __GNUC__  // ignore this switches of SAS/Storm
  66. #define __d0
  67. #define __d1
  68. #define __d2
  69. #define __d3
  70. #define __d4
  71. #define __d5
  72. #define __d6
  73. #define __d7
  74. #define __a0
  75. #define __a1
  76. #define __a2
  77. #define __a3
  78. #define __a4
  79. #define __a5
  80. #define __a6
  81. #define __a7
  82. #endif
  83.  
  84. #ifdef VBCC
  85. #define __d0 __reg("d0")
  86. #define __d1 __reg("d1")
  87. #define __d2 __reg("d2")
  88. #define __d3 __reg("d3")
  89. #define __d4 __reg("d4")
  90. #define __d5 __reg("d5")
  91. #define __d6 __reg("d6")
  92. #define __d7 __reg("d7")
  93. #define __a0 __reg("a0")
  94. #define __a1 __reg("a1")
  95. #define __a2 __reg("a2")
  96. #define __a3 __reg("a3")
  97. #define __a4 __reg("a4")
  98. #define __a5 __reg("a5")
  99. #define __a6 __reg("a6")
  100. #define __a7 __reg("a7")
  101. #endif
  102.  
  103.  /* for SAS/C we don't need this, for StormC this is done in the
  104.     makefile or projectfile */
  105.  
  106. /*                                                                       */
  107. /* ********************************************************************* */
  108.  
  109.  
  110. /* ********************************************************************* */
  111. /* Method 2: defining our own keywords                                   */
  112. /*                                                                       */
  113. #ifdef __SASC
  114.  
  115. #  define REG(r)     register __ ## r
  116. #  define GNUCREG(r)
  117. #  define SAVEDS     __saveds
  118. #  define ASM        __asm
  119. #  define REGARGS    __regargs
  120. #  define STDARGS    __stdargs
  121. #  define ALIGNED    __aligned
  122.  
  123. #else
  124. # ifdef __MAXON__
  125.  
  126. #  define REG(r)    register __ ## r
  127. #  define GNUCREG(r)
  128. #  define SAVEDS
  129. #  define ASM
  130. #  define REGARGS
  131. #  define STDARGS
  132. #  define ALIGNED
  133.  
  134. # else
  135. #  ifdef __STORM__
  136.  
  137. #   define REG(r)  register __ ## r
  138. #   define GNUCREG(r)
  139. #   define SAVEDS  __saveds
  140. #   define ASM
  141. #   define REGARGS
  142. #   define STDARGS
  143. #   define ALIGNED
  144.  
  145. #  else
  146. #   ifdef __GNUC__
  147.  
  148. #    define REG(r)
  149. #    define GNUCREG(r)  __asm( #r )
  150. #    define SAVEDS  __saveds
  151. #    define ASM
  152. #    define REGARGS __regargs
  153. #    define STDARGS __stdargs
  154. #    define ALIGNED __aligned
  155.  
  156. #   else
  157. #    ifdef VBCC
  158. /* VBCC ignore this switch */
  159. #     define __aligned
  160. #     define __asm
  161. #     define __regargs
  162. #     define __saveds
  163. #     define __stdargs
  164. #     define __register
  165. #     define GNUCREG(r)
  166. #     define REG(r)
  167. #     define SAVEDS
  168. #     define ASM
  169. #     define REGARGS
  170. #     define STDARGS
  171. #     define ALIGNED
  172.  
  173. #    else
  174. #     ifdef _DCC
  175. #      define __aligned
  176. #      define __stdargs
  177. #      define GNUCREG(r)
  178. #      define ASM
  179.  
  180. #     else  /* any other compiler, to be added here */
  181.  
  182. #      define REG(r)
  183. #      define GNUCREG(r)
  184. #      define SAVEDS
  185. #      define ASM
  186. #      define REGARGS
  187. #      define STDARGS
  188. #      define ALIGNED
  189.  
  190. #     endif /*   _DCC      */
  191. #    endif /*   VBCC      */
  192. #   endif /*  __GNUC__   */
  193. #  endif /*  __STORM__  */
  194. # endif /*  __MAXON__  */
  195. #endif /*  __SASC     */
  196. /*                                                                       */
  197. /* ********************************************************************* */
  198.  
  199.  
  200. /* Macros to define functions */
  201.  
  202. #define LIB_FCT_NAME(name) LIBFCTNAME ## _ ## name
  203.  
  204. #define LIB_FCT0(type, name) type __saveds ASM LIB_FCT_NAME(name) ( \
  205.   )
  206.  
  207. #define LIB_FCT1(type, name, a1) type __saveds ASM LIB_FCT_NAME(name) ( \
  208.   a1 \
  209.   )
  210. #define LIB_FCT2(type, name, a1,a2) type __saveds ASM LIB_FCT_NAME(name) ( \
  211.   a1, \
  212.   a2 \
  213.   )
  214. #define LIB_FCT3(type, name, a1,a2,a3) type __saveds ASM LIB_FCT_NAME(name) ( \
  215.   a1, \
  216.   a2, \
  217.   a3 \
  218.   )
  219. #define LIB_FCT4(type, name, a1,a2,a3,a4) type __saveds ASM name( \
  220.   a1, \
  221.   a2, \
  222.   a3, \
  223.   a4 \
  224.   )
  225. #define LIB_FCT5(type, name, a1,a2,a3,a4,a5) type __saveds ASM LIB_FCT_NAME(name) ( \
  226.   a1, \
  227.   a2, \
  228.   a3, \
  229.   a4, \
  230.   a5 \
  231.   )
  232. #define LIB_FCT6(type, name, a1,a2,a3,a4,a5,a6) type __saveds ASM name( \
  233.   a1, \
  234.   a2, \
  235.   a3, \
  236.   a4, \
  237.   a5, \
  238.   a6 \
  239.   )
  240. #define LIB_FCT7(type, name, a1,a2,a3,a4,a5,a6,a7) type __saveds ASM LIB_FCT_NAME(name) ( \
  241.   a1, \
  242.   a2, \
  243.   a3, \
  244.   a4, \
  245.   a5, \
  246.   a6, \
  247.   a7 \
  248.   )
  249.  
  250. #define LIB_FCT8(type, name, a1,a2,a3,a4,a5,a6,a7,a8) type __saveds ASM name( \
  251.   a1, \
  252.   a2, \
  253.   a3, \
  254.   a4, \
  255.   a5, \
  256.   a6, \
  257.   a7, \
  258.   a8 \
  259.   )
  260. #define LIB_FCT9(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9) type __saveds ASM LIB_FCT_NAME(name) ( \
  261.   a1, \
  262.   a2, \
  263.   a3, \
  264.   a4, \
  265.   a5, \
  266.   a6, \
  267.   a7, \
  268.   a8, \
  269.   a9 \
  270.   )
  271. #define LIB_FCT10(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) type __saveds ASM name( \
  272.   a1, \
  273.   a2, \
  274.   a3, \
  275.   a4, \
  276.   a5, \
  277.   a6, \
  278.   a7, \
  279.   a8, \
  280.   a9, \
  281.   a10 \
  282.   )
  283. #define LIB_FCT11(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) type __saveds ASM LIB_FCT_NAME(name) ( \
  284.   a1, \
  285.   a2, \
  286.   a3, \
  287.   a4, \
  288.   a5, \
  289.   a6, \
  290.   a7, \
  291.   a8, \
  292.   a9, \
  293.   a10, \
  294.   a11 \
  295.   )
  296. #define LIB_FCT12(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) type __saveds ASM name( \
  297.   a1, \
  298.   a2, \
  299.   a3, \
  300.   a4, \
  301.   a5, \
  302.   a6, \
  303.   a7, \
  304.   a8, \
  305.   a9, \
  306.   a10, \
  307.   a11, \
  308.   a12 \
  309.   )
  310. #define LIB_FCT13(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) type __saveds ASM LIB_FCT_NAME(name) ( \
  311.   a1, \
  312.   a2, \
  313.   a3, \
  314.   a4, \
  315.   a5, \
  316.   a6, \
  317.   a7, \
  318.   a8, \
  319.   a9, \
  320.   a10, \
  321.   a11, \
  322.   a12, \
  323.   a13 \
  324.   )
  325. #define LIB_FCT14(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) type __saveds ASM name( \
  326.   a1, \
  327.   a2, \
  328.   a3, \
  329.   a4, \
  330.   a5, \
  331.   a6, \
  332.   a7, \
  333.   a8, \
  334.   a9, \
  335.   a10, \
  336.   a11, \
  337.   a12, \
  338.   a13, \
  339.   a14 \
  340.   )
  341. #define LIB_FCT15(type, name, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) type __saveds ASM LIB_FCT_NAME(name) ( \
  342.   a1, \
  343.   a2, \
  344.   a3, \
  345.   a4, \
  346.   a5, \
  347.   a6, \
  348.   a7, \
  349.   a8, \
  350.   a9, \
  351.   a10, \
  352.   a11, \
  353.   a12, \
  354.   a13, \
  355.   a14, \
  356.   a15 \
  357.   )
  358.  
  359. #if LINKLIB != 1
  360. #define LIB_FCT(type,name,reg) register __ ## reg type name GNUCREG(reg)
  361. #define ASMREG LIB_FCT
  362. #else
  363. #define LIB_FCT(type,name,reg) type name
  364. #endif
  365.  
  366. #endif /* COMPILER_H */
  367.